<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>地图导航</title>
    <style>
        *{
         margin: 0;
         padding: 0;
        }
        #container{
         width: 100%;
         height: 100vh;
         background-color: white;
        }
    </style>
</head>
<body>
<div id="container"></div>
</body>
</html>

<script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: "b59f1a8482f33c8cfca30c0bc5d4615e",
    };
</script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=9e139cb65cf2a00dbe07092db72f6a37"></script>
<script type="text/javascript">
    // 1.0 地图初始化应该在地图容器 <div> 已经添加到 DOM 树之后
    var map = new AMap.Map("container", {
      zoom: 16, //地图级别
      center: [116.397428, 39.90923], //作为地图默认的中心点
    });

    // 2.0 规划路线方法
    function driving(start,end){
        // 2.1 路径规划
        const points = [
          { keyword: start}, // 起始点坐标
          { keyword: end}    // 终点坐标
        ]
        // 2.2 引入和创建驾车规划插件
        AMap.plugin(["AMap.Driving"], function () {
         // 2.2.1 创建插件对象
          const driving = new AMap.Driving({
            map: map,
            //驾车策略，包括 LEAST_TIME，LEAST_FEE, LEAST_DISTANCE,REAL_TRAFFIC
            policy: AMap.DrivingPolicy.LEAST_TIME
          });
          // 2.2.2 获取起终点规划线路
          driving.search(points, function (status, result) {
           //status：complete 表示查询成功，no_data 为查询无结果，error 代表查询错误
            if (status === "complete") {
              //查询成功时，result 即为对应的驾车导航信息
              console.log(result);
            } else {
              console.log("获取驾车数据失败：" + result);
            }
          });
        });

    }
</script>